/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.edu.agh.idrd.utils;

import java.util.ArrayList;
import java.util.List;
import pl.edu.agh.idrd.entity.Integrated;
import pl.edu.agh.idrd.entity.Interia;
import pl.edu.agh.idrd.hibernate.HibernateDAO;

/**
 *
 * @author Sergio
 */
public class IntegrateUtil {
    
    
    public static void integrate(String roadId, String description, String startDate, String finishDate){
        HibernateDAO<Integrated> integratedDAO = new HibernateDAO<Integrated>(Integrated.class);
        
      
        Integrated data = new Integrated();
        
        data.setRoadNumber(roadId);
        data.setDescription(description);
        data.setStartDate(startDate);                        
        data.setFinishDate(finishDate);
        
        String category = IdrdUtils.getCategory(description);               
        data.setCategory(category);
        
        String query = " where roadNumber = " + "'" + roadId + "'" + 
                " and category = " + "'" + category + "'" 
                    + " and startDate = " + "'" + startDate + "'";
        
        List<Integrated> list = integratedDAO.get(query);
        System.out.println("list empty = " + list.isEmpty());
        
        if(list.isEmpty()){
            integratedDAO.persist(data);
        }
            
                
        
    }
    
}
